import os.path

import numpy as np
from PIL import Image
from wordcloud import WordCloud


def display_word_cloud(data, word_cloud_mask_path, file_path, lang="ch"):
    if not os.path.exists(file_path):
        text = " ".join(data["tokenized"])
        wordcloud = WordCloud(background_color="white",
                              width=2000,
                              height=1500,
                              max_words=200,
                              max_font_size=80,
                              mask=np.array(Image.open(word_cloud_mask_path)),
                              contour_width=3,
                              collocations=False,
                              contour_color='steelblue',
                              font_path="data/%s.ttf" % lang,
                              ).generate(text)
        wordcloud.to_file(file_path)

    word_cloud_image = Image.open(file_path)
    word_cloud_image.show()
